#!/bin/bash

# Test data integrity after changing my address (sheep -y <myaddr>)

. ./common

MY_ADDR=`hostname -I | awk '{print $1}'`
ORIG_SHEEP_OPTIONS=$SHEEP_OPTIONS
NEW_SHEEP_OPTIONS="-n -y $MY_ADDR -l level=debug"

echo "1. start sheep with my address"
SHEEP_OPTIONS=$NEW_SHEEP_OPTIONS
_start_sheep 0
_wait_for_sheep 1
echo "----- cluster format ------"
_cluster_format -c 1
echo "----- cluster info -----"
$DOG cluster info | _filter_cluster_info | _filter_ip
echo "----- vdi create -----"
$DOG vdi create test 40M -P
echo "----- vdi list -----"
_vdi_list
echo "----- cluster shutdown -----"
$DOG cluster shutdown
_wait_for_sheep_stop

echo "2. start sheep with default"
SHEEP_OPTIONS=$ORIG_SHEEP_OPTIONS
_start_sheep 0
_wait_for_sheep 1
echo "----- cluster info -----"
$DOG cluster info | _filter_cluster_info | _filter_ip
echo "----- node info -----"
$DOG node info
echo "----- cluster shutdown -----"
$DOG cluster shutdown
_wait_for_sheep_stop

echo "3. start sheep with my address again"
SHEEP_OPTIONS=$NEW_SHEEP_OPTIONS
_start_sheep 0
_wait_for_sheep 1
echo "----- cluster info -----"
$DOG cluster info | _filter_cluster_info | _filter_ip
echo "----- vdi list -----"
_vdi_list
echo "----- cluster shutdown -----"
$DOG cluster shutdown
_wait_for_sheep_stop
